
class Solution
{
public:
    string longestPalindrome(string s)
    {
        int maxSize = 1;
        int begin = 0, end = 0;
        for (int it = 0; it < s.size(); ++it)
        {
            int size = 1;
            int _begin = it, _end = it;
            while (_end + 1 < s.size() &&
                s[_begin] == s[_end + 1])
            {
                ++_end;
                ++size;
            }
            // 
            for (; 0 <= _begin - 1 && _end + 1 < s.size();
                --_begin, ++_end, size += 2)
            {
                if (s[_begin - 1] != s[_end + 1])
                {
                    break;
                }
            }
            if (maxSize < size)
            {
                maxSize = size;
                begin = _begin, end = _end;
            }
        }
        string ans;
        for (; begin <= end; ++begin)
        {
            ans.push_back(s[begin]);
        }
        return ans;
    }
};
